#include <stdio.h>
#include "leb128.h"

int  size_leb128(const char *s)
{
	int i=0;
	while(i<5&&s[i]&0x80) i++;

	return i+1;
}
int  value_leb128(const char *s)
{
	int i=0,v=0;
	while(i<5&&s[i]&0x80) i++;

	goto l1;
	 do
	{
		v<<=7;
l1:
		v|=(s[i]&0x7f);
		if(i==0) break;
		i--;
	}while(1);

	return v;
}

void print_leb128(const char *s)
{
	printf("%04x",value_leb128(s));
}
int  sprint_leb128( char *buffer,const char *s)
{

	return sprintf(buffer,"%04x",value_leb128(s));
}